package org.example.multiThreading.getAndSetThread;

public class TestThreadName {

    public static void main(String[] args) {
        ThreadName threadName = new ThreadName();
        //设置线程名称
        threadName.setName("1号线程");
        threadName.start();
        //通过构造方法改变线程名称
        ThreadName threadName1 = new ThreadName("二号线程");
        threadName1.start();
    }

}

class ThreadName extends Thread{

    public ThreadName(){}

    public ThreadName(String name){
        super(name);
    }

    @Override
    public void run(){
        //使用this.getId()获取线程id,this.getName()获取线程名称
        System.out.println(this.getId()+","+this.getName());
        //使用Thread.currentThread().getId()获取线程id和Thread.currentTread().getName()获取线程名称
        System.out.println(Thread.currentThread().getId()+","+Thread.currentThread().getName());
    }
}